﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace ECommerce.Common
{
    public sealed class SiteCookie
    {
        private static System.Web.HttpContext Current
        {
            get
            {
                return System.Web.HttpContext.Current;
            }
        }

        public static string MemberLoginName
        {
            get
            {
                return (Current.Request.Cookies["MemberLoginName"] == null) ? null : Current.Request.Cookies["MemberLoginName"].Value;
            }
            set
            {
                HttpCookie cookie = new HttpCookie("MemberLoginName", value);
                cookie.Expires = DateTime.Now.AddHours(10);
                Current.Response.Cookies.Add(cookie);
            }
        }

        public static string Password
        {
            get
            {
                return (Current.Request.Cookies["MemberPassword"] == null) ? null : Current.Request.Cookies["MemberPassword"].Value;
            }
            set
            {
                HttpCookie cookie = new HttpCookie("MemberPassword", value);
                cookie.Expires = DateTime.Now.AddHours(10);
                Current.Response.Cookies.Add(cookie);

            }
        }

        public static string ShoppingCart
        {
            get
            {
                return (Current.Request.Cookies["ShoppingCart"] == null) ? null : Current.Request.Cookies["ShoppingCart"].Value;
            }
            set
            {
                HttpCookie cookie = new HttpCookie("ShoppingCart", value);
                cookie.Expires = DateTime.Now.AddDays(1);
                Current.Response.Cookies.Add(cookie);

            }
        }



        public static void Clear()
        {
            HttpCookie cookie = new HttpCookie("MemberLoginName");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Current.Response.Cookies.Add(cookie);

            cookie = new HttpCookie("MemberPassword");
            cookie.Expires = DateTime.Now.AddDays(-1);
            Current.Response.Cookies.Add(cookie);
        }
    }
}
